﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Common;
using System.Data;

namespace RegisterationSystem.Space_Education
{
    public partial class _main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        /// <summary>
        /// 绑定招生数
        /// </summary>
        void Bind()
        {
            //IsDelete : 是否删除(0未删除 1删除)
            //IsRecord : 是否代录
            //IsMatured: 是否足龄
            //SchID    : 所属学校
            //Status   : 信息状态(0未分配1已分配2初审通过)
            RParams RP = new RParams();
            //今日登记学生数量
            lbljrCount.Text = DBAction.GetDTFromSQL("select * from Students where datediff(day, RegisterTime,getdate())=0 and IsDelete=0").Rows.Count.ToString();
            //本周登记学生数量
            lblbzCount.Text = DBAction.GetDTFromSQL("select * from Students where datediff(week, RegisterTime,getdate())=0 and IsDelete=0").Rows.Count.ToString();
            //已登记学生总数量
            lblybCount.Text = DBAction.GetDTFromSQL("select * from Students where IsDelete=0").Rows.Count.ToString();
            //代录登记学生数量
            RP.Add("IsRecord", true, SqlDbType.Bit);
            RP.Add("IsDelete", false, SqlDbType.Bit);
            RP.Add("IsMatured", true, SqlDbType.Bit);
            lbldlCount.Text = DBAction.GetDTFromSQL("select * from Students where IsRecord=@IsRecord and IsDelete=@IsDelete ", RP).Rows.Count.ToString();
            //分配到校学生数量
            RP.Add("SchID", 0, SqlDbType.Int);
            lblfpCount.Text = DBAction.GetDTFromSQL("select * from Students where SchID >@SchID and IsDelete=@IsDelete and IsMatured=@IsMatured", RP).Rows.Count.ToString();
            //符合要求学生数量
            RP.Add("Status", 2, SqlDbType.Int);
            lblfhCount.Text = DBAction.GetDTFromSQL("select * from Students where Status =@Status and IsDelete=@IsDelete and IsMatured=@IsMatured", RP).Rows.Count.ToString();
            //不足龄学生总数量
            RP.Items.Clear();
            RP.Add("IsRecord", true, SqlDbType.Bit);
            RP.Add("IsDelete", false, SqlDbType.Bit);
            RP.Add("IsMatured", false, SqlDbType.Bit);
            lblbzCoubt.Text = DBAction.GetDTFromSQL("select * from Students where IsMatured =@IsMatured and IsDelete=@IsDelete", RP).Rows.Count.ToString();
            //超出计划学生数量
            string schcount = DBAction.GetDTFromSQL("select sum(Count) from SchoolInfo").Rows[0][0].ToString();
            lblccCount.Text = Convert.ToInt32(lblfpCount.Text) - Convert.ToInt32(schcount) > 0 ? (Convert.ToInt32(lblfpCount.Text) - Convert.ToInt32(schcount)).ToString() : "0";
            //区内学生数量
            RP.Items.Clear();
            RP.Add("IsRecord", true, SqlDbType.Bit);
            RP.Add("IsDelete", false, SqlDbType.Bit);
            RP.Add("IsMatured", true, SqlDbType.Bit);
            RP.Add("HouseAreaID", 0, SqlDbType.Int);
            lblqnCount.Text = DBAction.GetDTFromSQL("select * from Students where HouseAreaID = @HouseAreaID and IsDelete=@IsDelete", RP).Rows.Count.ToString();
            //市内区外学生数量
            RP.Items.Clear();
            RP.Add("IsRecord", true, SqlDbType.Bit);
            RP.Add("IsDelete", false, SqlDbType.Bit);
            RP.Add("IsMatured", true, SqlDbType.Bit);
            RP.Add("HouseAreaID", 1, SqlDbType.Int);

            RP.Add("IsSelf", 1, SqlDbType.Int);//无住房

            lblsnCount.Text = DBAction.GetDTFromSQL("select * from Students where HouseAreaID =@HouseAreaID and IsDelete=@IsDelete and IsSelf=@IsSelf", RP).Rows.Count.ToString();
            //省外市外学生数量
            RP.Items.Clear();
            RP.Add("IsRecord", true, SqlDbType.Bit);
            RP.Add("IsMatured", true, SqlDbType.Bit);
            RP.Add("HouseAreaID", 2, SqlDbType.Int);
            RP.Add("IsDelete", false, SqlDbType.Bit);
            lblswCount.Text = DBAction.GetDTFromSQL("select * from Students where HouseAreaID =@HouseAreaID and IsDelete=@IsDelete", RP).Rows.Count.ToString();
        }
    }
}